﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Mechanics {
    import Mechanics.GameMechanicInterfaces.*;
    import flash.utils.*;
    import Classes.*;
    import Classes.util.*;
    import Mechanics.ClientDisplayMechanics.*;
    import Modules.crew.ui.*;
    import Mechanics.GameEventMechanics.*;
    import Mechanics.Transactions.*;

    public class MechanicManager {

        public static const DATA_NOT_INITIALIZED:String = "Data for this mechanic has not been initialized";
        public static const MECHANIC_SLOTS:String = "slots";
        public static const MECHANIC_STORAGE:String = "storage";
        public static const MECHANIC_ROLL_CALL:String = "rollCall";
        public static const ALL:String = "all";
        public static const PLAY:String = "GMPlay";

        private static var m_instance:MechanicManager = null;
        private static var m_allowedMechanicClasses:Array = [ExampleMechanicImplementation, DialogGenerationMechanic, CatalogGenerationMechanic, StorageMechanicImplementation, EffectRenderer, StagePickEffectRenderer, AnimatedEffectRenderer, HarvestReadyIndicator, MultiAssetRenderer, MultiPickMechanic, StorageSupplyMechanic, SlotMechanicImplementation, DictionaryDataMechanicImplementation, FriendRewardsDialogMechanic, ZooUnlockDialogMechanic, GatedStorageMechanic, NeighborVisitRewardMechanic, MerchantCustomerMechanic, StorageStateHarvestMechanic, MallHarvestMechanic, MallStorageMechanic, UpgradeMechanic, MallUpgradeMechanic, ZooUnlockDialogMechanic, RollCallDialogMechanic, RollCallDialogIntroMechanic, RollCallDataMechanic, RollCallDialog, TieredDooberMechanic, DooberMechanic, NotifyGuideMechanic];

        public function MechanicManager(){
            if (MechanicManager.m_instance != null){
                throw (new Error("Attempting to instantiate more than one MechanicManager"));
            };
        }
        public static function getInstance():MechanicManager{
            if (!MechanicManager.m_instance){
                MechanicManager.m_instance = new (MechanicManager)();
            };
            return (m_instance);
        }

        public function getMechanicInstance(_arg1:IMechanicUser, _arg2:String, _arg3:String):IGameMechanic{
            var _local4:IGameMechanic;
            var _local6:Class;
            var _local5:MechanicConfigData = _arg1.getMechanicConfig(_arg2, _arg3);
            if (_local5){
                _local6 = (getDefinitionByName(("Mechanics.GameEventMechanics." + _local5.className)) as Class);
                _local4 = new (_local6)();
                _local4.initialize(_arg1, _local5);
            };
            return (_local4);
        }
        public function createDisplayMechanicInstance(_arg1:IMechanicUser, _arg2:MechanicConfigData):IClientGameMechanic{
            var _local3:IClientGameMechanic;
            var _local4:Class;
            if (_arg2.className != ""){
                _local4 = (getDefinitionByName(("Mechanics.ClientDisplayMechanics." + _arg2.className)) as Class);
                _local3 = new (_local4)();
                _local3.initialize(_arg1, _arg2);
            };
            return (_local3);
        }
        public function handleAction(_arg1:IMechanicUser, _arg2:String, _arg3:Array=null):Boolean{
            var _local5:Array;
            var _local6:IActionGameMechanic;
            var _local7:String;
            var _local8:MechanicActionResult;
            var _local4:Boolean;
            if (!Global.isTransitioningWorld){
                _local5 = _arg1.getPrioritizedMechanicsForGameEvent(_arg2);
                if (((_local5) && ((_local5.length > 0)))){
                    for each (_local7 in _local5) {
                        _local6 = (this.getMechanicInstance(_arg1, _local7, _arg2) as IActionGameMechanic);
                        if (_local6.hasOverrideForGameAction(_arg2)){
                            _local8 = _local6.executeOverrideForGameEvent(_arg2, _arg3);
                            _local4 = _local8.actionSuccess;
                            if (((!((_local8 == null))) && (_local8.sendTransaction))){
                                GameTransactionManager.addTransaction(new TMechanicAction((_arg1 as MechanicMapResource), _local7, _arg2, _local8.transactionParams));
                            };
                            if (((!((_local8 == null))) && (!(_local8.continueActionExecution)))){
                                _local6 = null;
                                break;
                            };
                        };
                    };
                };
            };
            return (_local4);
        }

    }
}//package Mechanics 
